<template>
  <div style="border-radius: 4px; border: 1px solid black; text-align: left; height: 200px">
    <div style="display:inline-block; float: left; margin-top: 15px; margin-left: 15px" >
      <img :src="article.coverImage" width="220px" height="170px">
    </div>
    <div style="display:inline-block;  width: 65%;
                margin-left: 14px; margin-top: 10px;
                white-space: nowrap; overflow: hidden;text-overflow: ellipsis;">
       <a @click="getArticlePageById(article.id)"
          style="text-decoration: none; font-family: 楷体; font-size: 22px; cursor: pointer">
         {{article.title}}
       </a>
    </div>
    <div style="display:inline-block;
          width: 65%; margin-left: 14px; margin-top: 3px">
      <p>
      {{article.content}}
      </p>
    </div>
    <div style="margin-left: 248px; margin-bottom: 8px">
<!--      todo 标签栏占位-->
      <div v-show="article.tags.length != 0">
        <div style="display: inline-block">
          标签栏: &nbsp;
        </div>
        <div style="display: inline-block">
          <ul>
            <li v-for="item in article.tags" style="display: inline-block; margin-right: 20px">
              <el-button size="mini">{{ item }}</el-button>
            </li>
          </ul>
        </div>

      </div>
    </div>
    <div style="display:inline-block; position: relative">
        <div style="display: inline-block; margin-left: 13px;  margin-right: -9px">
          <el-avatar :size="40" :src=article.avatar style="display: inline-block"></el-avatar>
        </div>

        <div style="display: inline-block;
                    margin-left: 20px; position: absolute; top: 10px; width: 300px;"
        >
          <div style="display: inline-block; width: 100px; white-space: nowrap; overflow: hidden;text-overflow: ellipsis;">
            {{article.userName}}
          </div>
          <div style="display: inline-block; position: absolute; top: 2px; width: 400px">
            <i :class=star style="cursor: pointer; font-size: 16px; color: red" @click="likeOrDislike">{{ article.likesNumber }} </i>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <span style="font-size: 17px"> {{article.updateTime}}</span>
          </div>
        </div>
    </div>



  </div>

</template>

<script>
export default {
  name: "articleComponent",
  props:{
    article: Object,
  },
  methods: {
    likeOrDislike: function (){
      if(this.like == 0){
        this.like=1;
        this.article.likesNumber += 1;
        this.star="el-icon-star-on"
      }else{
        this.like=0;
        this.article.likesNumber -= 1;
        this.star="el-icon-star-off"
      }
    },
    getArticlePageById: function (id){
      this.$router.push({path: '/article/'+id})
    }
  },
  data(){
    return{
        like: 0,
        star: "el-icon-star-off",
    }
  }
}
</script>

<style scoped>
a{
  color: black;
}
a:hover{
  color: #E6A23C;
}
p {
  position:relative;
  line-height:1.5em;
  /* 高度为需要显示的行数*行高，比如这里我们显示两行，则为3 */
  height:4.5em;
  overflow:hidden;
}
p:after {
  content:"...";
  position:absolute;
  bottom:0;
  right:0;
  padding: 0 5px;
  background-color: #fff;
}

</style>